package com.class06.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/servletB")
public class ServletB extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
//        1、如何获取session
        HttpSession session = req.getSession();
        System.out.println("sessionId:" + session.getId());
//        2、session中存值
        session.setAttribute("username", "zhangsan");
//        3、session中修改值
        session.setAttribute("username", "lisi");
//        4、删除session中的键值对
        session.removeAttribute("username");

    }
}
